package cn.njyd.corejava.thread.myday04;

import java.util.Map;

class MyThreadLocal {
    ThreadLocal<String> tl = new ThreadLocal<>();
}


public class ThreadLocalDemo01 {
    public static void main(String[] args) {
        MyThreadLocal myThreadLocal = new MyThreadLocal();
        Thread t1 = new Thread(()-> {
            myThreadLocal.tl.set(Thread.currentThread().getName());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+myThreadLocal.tl.get());
            myThreadLocal.tl.remove();
        },"Thread-1");
        t1.start();
        Thread t2 = new Thread(()->{
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+myThreadLocal.tl.get());
            myThreadLocal.tl.set(Thread.currentThread().getName()+Thread.currentThread().getName());
            System.out.println(myThreadLocal.tl.get());
        },"Thread-2");
        t2.start();

    }
}
